Skip to content

fix(mappers): dot-notation field overrides now resolve through collection element types#92

Merged
j-d-ha merged 2 commits intomainfrom
fix/Dot-notation-field-overrides-do-not-work-for-collection-element-members
Apr 8, 2026
Merged

fix(mappers): dot-notation field overrides now resolve through collection element types#92
j-d-ha merged 2 commits intomainfrom
fix/Dot-notation-field-overrides-do-not-work-for-collection-element-members

Conversation

@j-d-ha
Copy link
Copy Markdown
Collaborator

@j-d-ha j-d-ha commented Apr 8, 2026

🚀 Pull Request

📋 Summary

Fixes two bugs that prevented [DynamoField] dot-notation overrides from working when an intermediate path segment is a collection (List<T>, T[], Dictionary<string, T>, etc.).

Example that now works:

[DynamoMapper]
[DynamoField("Contacts.VerifiedAt", Format = "yyyy-MM-dd")]
[DynamoField("Contacts.Name", AttributeName = "contact_name")]
public static partial class CustomerMapper { ... }

Bug 1ValidatePath() in ModelClassInfo.cs traversed directly into List<CustomerContact> when resolving the Contacts segment, causing a false DM0008 diagnostic. Fix: after the existing nullable unwrap, now also calls CollectionTypeAnalyzer.Analyze() to unwrap to the element type before advancing.

Bug 2CreateCollectionStrategy() in TypeMappingStrategyResolver.cs created a fresh NestedAnalysisContext with an empty path, so GetFieldOptionsForProperty("VerifiedAt") looked up "VerifiedAt" instead of "Contacts.VerifiedAt". Additionally, CollectionTypeAnalyzer.ValidateElementType() called NestedObjectTypeAnalyzer.Analyze() with the dummy property name "element", which further corrupted the path. Fix: a new AnalyzeElementType() method bypasses the path-append that Analyze() performs, and callers supply the correct path prefix up-front.

The fix applies uniformly to List<T>, T[], Dictionary<string, T>, and collections nested within nested objects.


✅ Checklist

  • My changes build cleanly
  • I've added/updated relevant tests
  • I've added/updated documentation or README
  • I've followed the coding style for this project
  • I've tested the changes locally (if applicable)

🧪 Related Issues or PRs

Closes #91


💬 Notes for Reviewers

Three source files changed:

  • ModelClassInfo.cs — 4-line addition in ValidatePath(), no logic removed
  • CollectionTypeAnalyzer.cs — swap Analyze(..., "element", ...) for new AnalyzeElementType(...)
  • NestedObjectTypeAnalyzer.cs — new internal AnalyzeElementType() method + one-line change in AnalyzeForInline() to pass contextWithAncestor.WithPath(property.Name) for collection properties within nested objects

6 new snapshot tests in CollectionDotNotationVerifyTests.cs cover List<T>, T[], Dictionary<string, T>, multiple overrides on the same element type, and a DM0008 regression guard for invalid element property names.

j-d-ha added 2 commits April 7, 2026 20:24
… properties

- Implement `AnalyzeElementType` to correctly resolve path prefixes for collection elements.
- Update `TypeMappingStrategyResolver` to include collection property paths in context.
- Add `DM0008` diagnostic for invalid properties within collection element paths.
- Enhance documentation with examples of collection element dot-notation mappings.
- Include test cases validating dot-notation overrides for nested list, array, and dictionary elements.
…support

- Extend documentation to clarify dot-notation usage for collection element properties.
- Update `DM0008` diagnostic details with support for nested collection element paths.
Copy link
Copy Markdown
Contributor

@ncipollina ncipollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! 🎣

@j-d-ha j-d-ha merged commit 157a306 into main Apr 8, 2026
3 checks passed
@j-d-ha j-d-ha deleted the fix/Dot-notation-field-overrides-do-not-work-for-collection-element-members branch April 8, 2026 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dot-notation field overrides do not work for collection element members

2 participants